package com.hzdy.master.repository.mysql;

import com.hzdy.master.entity.OID.OID;
import com.hzdy.master.entity.table.CreateTable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LALA
 * Date: 2019-03-11
 * Time: 9:58
 */

public interface OIDRepository  extends JpaRepository<OID,Long> {

    @RestResource(path="findBySearch",rel="findBySearch")
    @Query(value = "select * from oid where 1=1 " +
            "and ( :name is NULL or name like CONCAT('%', :name ,'%'))"+
            "and ( :startDate is NULL or createDate >= :startDate)"+
            "and ( :endDate is NULL or createDate <= :endDate)",
            nativeQuery = true)
    Page<OID> findAllByCreateDateBetweenAndName(
            @Param("name") String name,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate,
            Pageable pageable);
}
